import cv2
import numpy as np

img = cv2.imread('bilibili.png')

#先腐蚀再膨胀
kernel = np.ones((40,40),np.uint8)
opening = cv2.morphologyEx(img, cv2.MORPH_OPEN, kernel)
cv2.imshow('opening',opening)
cv2.waitKey(0)
cv2.destroyAllWindows()